import std.container.array;
import std.stdio;

import std.algorithm.searching;

/*void shoe(ref Array!int aa)
{
     writeln (aa.length);
     
     write("aa is [ ");
     foreach(i; aa)
     {
     
        write(i, ",");
     }
     writeln("]");
}*/

void shoe(ref Array!int aa)
{
     writeln (aa.length);
     
     write("aa is [ ");
     for(int i = 0; i < aa.length; ++i)
     {
     
        write(i, " = ", aa[i], " ,");
     }
     writeln("]");
}

void main()
{
    Array!int aa = Array!int([1,2,5,5,3,5,8,6,4,5,6]);
    writeln (aa.length);
    
    aa.insertBack(7);
    
    shoe(aa);
     
     aa.insertBefore(aa[0..0],0);
     
     shoe(aa);
     
     aa.linearRemove(aa[0..1]);
     
     shoe(aa);
     
     writeln("\n\n rm find");
     auto rm = find(aa[0..$],5);
     
     aa.linearRemove(rm[0..1]);
     
     shoe(aa);
     
      Array!int _ctxs = Array!int([1,2,5,5,3,5,8,6,4,5,6]);
      shoe(_ctxs);
     void findAndremove(int j)
		{
			int i = j;
			for (; i < _ctxs.length; ++i, ++j) {
				//auto ctx = cast(ContextType!H)_ctxs[i];
				if(_ctxs[i] == 5) {
                                    _ctxs.linearRemove(_ctxs[i..(i + 1)]);
                                    --i;
                                    writeln("i = ", i,  " length = ",_ctxs.length, "  index = ",j);
				}
			}
			
		}
     findAndremove(0);
    shoe(_ctxs);
}
